window.addEventListener('load',function(){
    var app=new Vue({
        el:'#app',
        data:{
            query:'',
            musicList:[],
            musicUrl:'',
            picUrl:'',
            hotComments:[],
            isPlaying:false,
            isShow:false,
            mvUrl:''
        },
        methods:{
            searchMusic:function(){
                var _this=this;
                axios.get('https://autumnfish.cn/search?keywords='+this.query)
                .then(function(response){
                    // console.log(response);
                    _this.musicList=response.data.result.songs;
                    console.log(response.data.result.songs);
                },function(err){
                    console.log(err);
                })
            },
            playMusic:function(musicId){
                // console.log(musicId);
                var _this=this;
                // 获取歌曲地址
                axios.get("https://autumnfish.cn/song/url?id=" + musicId)
                .then(function(response){
                //    console.log(response.data.data[0].url);
                   _this.musicUrl=response.data.data[0].url
                },function(err){
                    console.log(err);
                })
                // 获取歌曲封面地址
                axios.get("https://autumnfish.cn/song/detail?ids=" + musicId)
                .then(function(response){
                    // console.log(response);
                    _this.picUrl=response.data.songs[0].al.picUrl;
                },function(err){
                    console.log(err);
                })
                // 获取歌曲评论
                axios.get("https://autumnfish.cn/comment/hot?type=0&id=" + musicId)
                .then(function(response){
                    // console.log(response.data.hotComments);
                    _this.hotComments=response.data.hotComments;
                })
            },
            play:function(){
                // console.log(1);
                this.isPlaying=true;
            },
            pause:function(){
                // console.log(2);
                this.isPlaying=false;
            },
            playMv:function(mvid){
                var _this=this;
                axios.get("https://autumnfish.cn/mv/url?id=" + mvid)
                .then(function(response){
                    console.log(response.data.data.url);
                    _this.isShow=true
                    _this.mvUrl=response.data.data.url
                },function(err){
                    console.log(err);
                })
            },
            hide:function(){
                this.isShow=false;
            }
        }
    })
})